import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'mealModel.dart';

class MealDetail extends StatefulWidget {
  final Meal meal;
  final Function like;
  MealDetail({Key? key, required this.meal, required this.like})
      : super(key: key);

  @override
  _MealDetailState createState() => _MealDetailState();
}

class _MealDetailState extends State<MealDetail> {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Center(
          child: Text(widget.meal.name),
        ),
        actions: [
          widget.meal.isCollect == true
              ? IconButton(
                  icon: Icon(
                    Icons.favorite,
                    color: Colors.red,
                    size: 35,
                  ),
                  tooltip: '点击取消收藏',
                  onPressed: () {
                    widget.like();
                    setState(() {
                      // do nothing
                    });
                  })
              : IconButton(
                  icon: Icon(
                    Icons.favorite_outline,
                    color: Colors.black12,
                    size: 35,
                  ),
                  tooltip: '点击收藏',
                  onPressed: () {
                    widget.like();
                    setState(() {
                      // do nothing
                    });
                  }),
          // 被debug挡住了，放几个占位符
          Opacity(
            opacity: 0,
            child: Icon(Icons.add),
          ),
          Opacity(
            opacity: 0,
            child: Icon(Icons.add),
          ),
          Opacity(
            opacity: 0,
            child: Icon(Icons.add),
          ),
        ],
      ),
      body: Container(
        child: Column(
          children: [
            Row(
              mainAxisAlignment: MainAxisAlignment.spaceAround,
              children: [
                Expanded(
                  child: Column(
                    children: [
                      widget.meal.url == null
                          ? Image.asset('images/fail.png')
                          : Image.network(
                              widget.meal.url!,
                              errorBuilder: (context, error, stackTrace) {
                                return Image.asset('images/fail.png');
                              },
                            ),
                    ],
                  ),
                ),
                Expanded(
                    child: Column(
                  mainAxisAlignment: MainAxisAlignment.spaceBetween,
                  children: [
                    Row(mainAxisAlignment: MainAxisAlignment.start, children: [
                      Text('单价： ￥${widget.meal.price}',
                          style: TextStyle(color: Colors.red))
                    ]),
                    Row(
                      mainAxisAlignment: MainAxisAlignment.start,
                      children: [
                        Text(
                          '配送范围：  10千米',
                          style: TextStyle(color: Colors.teal),
                        )
                      ],
                    ),
                    Row(mainAxisAlignment: MainAxisAlignment.start, children: [
                      Text('当日午餐',
                          style: TextStyle(
                            color: widget.meal.mealType == '当日午餐'
                                ? Colors.redAccent
                                : Colors.black26,
                          )),
                      Padding(padding: EdgeInsets.all(20)),
                      Text('次日午餐',
                          style: TextStyle(
                            color: widget.meal.mealType == '次日午餐'
                                ? Colors.redAccent
                                : Colors.black26,
                          )),
                    ]),
                    Row(mainAxisAlignment: MainAxisAlignment.start, children: [
                      Text('次日晚餐',
                          style: TextStyle(
                            color: widget.meal.mealType == '次日晚餐'
                                ? Colors.redAccent
                                : Colors.black26,
                          )),
                    ]),
                  ],
                ))
              ],
            ),
            Divider(),
            Row(
              mainAxisAlignment: MainAxisAlignment.start,
              children: [
                Text(
                  '美食介绍：',
                  style: TextStyle(color: Colors.orange),
                )
              ],
            ),
            Row(
              mainAxisAlignment: MainAxisAlignment.start,
              children: [
                Expanded(
                    child: Container(
                  child: Padding(
                      padding: EdgeInsets.all(16.0),
                      child: Row(children: [
                        Expanded(
                          child: Center(
                              child: Text(
                            '精选日本仙台和牛， 烧制三分熟切片， 淋秘制酱汁， '
                            '配以新泻县鱼沼产越光米， 鲜香嫩滑回味留甘， 限量供应',
                          )),
                        )
                      ])),
                ))
              ],
            ),
            Row(
              mainAxisAlignment: MainAxisAlignment.start,
              children: [
                Text(
                  '产品图片：',
                  style: TextStyle(color: Colors.orange),
                )
              ],
            ),
            Row(
              mainAxisAlignment: MainAxisAlignment.start,
              children: [
                Image.asset(
                  'images/niupai.jpg',
                  width: 80,
                  height: 80,
                ),
                Padding(padding: EdgeInsets.all(20)),
                Image.asset(
                  'images/jiugui.jpg',
                  width: 80,
                  height: 80,
                ),
              ],
            ),
            Divider(),
            Row(
              mainAxisAlignment: MainAxisAlignment.spaceAround,
              children: [
                ElevatedButton(
                    style: ButtonStyle(
                        backgroundColor: MaterialStateProperty.all<Color>(
                            Colors.deepOrangeAccent)),
                    onPressed: () {
                      Navigator.pop(context);
                    },
                    child: Text(
                      '退出',
                      style: TextStyle(color: Colors.white),
                    )),
                ElevatedButton(
                    style: ButtonStyle(
                        backgroundColor: MaterialStateProperty.all<Color>(
                            Colors.deepOrange)),
                    onPressed: () {},
                    child: Text(
                      '查看商家',
                      style: TextStyle(color: Colors.black),
                    ))
              ],
            )
          ],
        ),
      ),
    );
  }
}
